<template>
  <a-layout style="min-height: 100vh">
    <a-layout-sider collapsible v-model:collapsed="collapsed">
      <div class="logo">
        <span class="logo-title">AI投资教育平台</span>
      </div>
      <a-menu theme="dark" mode="inline" :selectedKeys="[activeMenu]" @click="onMenuClick">
        <a-menu-item key="profile">个人主页</a-menu-item>
        <a-menu-item key="chat">投资问答</a-menu-item>
        <a-menu-item key="knowledge">知识科普</a-menu-item>
      </a-menu>
    </a-layout-sider>
    <a-layout>
      <a-layout-header class="header">
        <div class="user-info">
          <a-avatar style="background-color: #87d068; margin-right: 8px;">t</a-avatar>
          <span>test</span>
          <span class="user-email">13426123123@qq.com</span>
          <a-button type="link" @click="logout">退出登录</a-button>
        </div>
      </a-layout-header>
      <a-layout-content class="content-layout">
        <div class="content-box">
          <component :is="currentComponent" />
        </div>
      </a-layout-content>
    </a-layout>
  </a-layout>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'
import Profile from './profile.vue'
import Chat from './chat.vue'
import Knowledge from './knowledge.vue'

const collapsed = ref(false)
const activeMenu = ref('profile')
const router = useRouter()

const componentMap = {
  profile: Profile,
  chat: Chat,
  knowledge: Knowledge
}
const currentComponent = computed(() => componentMap[activeMenu.value])

function onMenuClick({ key }) {
  activeMenu.value = key
}
function logout() {
  // 可根据实际情况清除token等
  router.replace('/')
}
</script>

<style scoped>
.logo {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #fff;
  font-weight: bold;
  margin: 16px 0;
}
.logo-title {
  letter-spacing: 2px;
}
.header {
  background: #fff;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 64px;
  box-shadow: 0 2px 8px #f0f1f2;
}
.user-info {
  display: flex;
  align-items: center;
  font-size: 16px;
}
.user-email {
  margin-left: 16px;
  color: #888;
}
.content-layout {
  margin: 24px 16px 0;
}
.content-box {
  background: #fff;
  min-height: 360px;
  padding: 24px;
  border-radius: 8px;
  box-shadow: 0 2px 8px #f0f1f2;
}
</style>
